<%@ page import="com.xyc.mapper.OrderMapper" %>
<%@ page import="com.xyc.pojo.Order" %>
<%@ page import="org.springframework.context.ApplicationContext" %>
<%@ page import="org.springframework.context.support.ClassPathXmlApplicationContext" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.List" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta name="viewport">
    <title>购物车</title>
    <link rel='stylesheet' href='css/buycar.css'/>
    <link rel='stylesheet' href='css/buycar_table.css'/>
    <link rel='stylesheet' href='http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css'/>

    <script src='js/jquery.min.js'></script>
    <script src='http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js'></script>
    <script src='js/myCookie.js'></script>

    <script type="text/javascript">
        var count = $('#count').val();
        var priceSingle = $('#price').text();
    </script>

    <style>
        th {
            text-align: center;
        }
    </style>
</head>
<body>
<h1><a href="index.jsp" style="text-decoration:none;">&nbsp;华为商城</a>
    <a href="p40pro+.html" style="text-decoration: none;">
        <small style="color:blue;">&nbsp;返回</small>
    </a>
</h1>

<div>
    <table class="table table-bordered table-hover table-condensed">
        <caption style="font-size:20px;font-weight:bold;">&nbsp;&nbsp;订单信息</caption>
        <thead>
        <tr class="info">
            <th>序号</th>
            <th>创建时间</th>
            <th>商品图片</th>
            <th>备注</th>
            <th>数量</th>
            <th>单价(元)</th>
            <th>优惠(元)</th>
            <th>价格(元)</th>
            <th>操作</th>
            <th>选择</th>
        </tr>
        </thead>

        <%
            ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-dao.xml");
            OrderMapper orderMapper = ctx.getBean("orderMapper", OrderMapper.class);
            List<Order> orderList = orderMapper.findOrder();
            for (int i = 0; i < orderList.size(); i++) {
                Order order = orderList.get(i);
        %>

        <tbody>
        <tr class="text-center">
            <td><%=order.getOrder_id()%>
            </td>
            <%
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                String create_time = sdf.format(order.getCreate_time());
            %>
            <td><%=create_time%>
            </td>

            <td>
                <img src="imgs/p40/<%=order.getPic_name()%>" style="width:50px;height:50px;"/>
            </td>
            <td><%=order.getOrder_describe()%>
            </td>
            <td><%=order.getCount()%>
                &nbsp;&nbsp;
                <a href="add?id_add=<%=order.getOrder_id()%>"
                <span class="glyphicon glyphicon-plus"></span>
                </a>
                <a href="minus?id_minus=<%=order.getOrder_id()%>"
                <span class="glyphicon glyphicon-minus"></span>
                </a>
            </td>
            <td><%=order.getPrice()%>
            </td>
            <td><%=order.getDiscount()%>
            </td>
            <td><%=order.getLast_price()%>
            </td>
            <td>
                <a href="delOrder?id_del=<%=order.getOrder_id()%>"
                   onclick="return confirm('确认删除<%=order.getOrder_describe()%>吗?')">
                    <btn class="btn btn-success">删除</btn>
                </a>
            </td>
            <td>
                <a href="#" class="btn btn-info">
                    <span class="glyphicon glyphicon-heart"></span>&nbsp;购买
                </a>
            </td>

        </tr>
        <%}%>
        </tbody>
    </table>
</div>

<br>
<%
    Integer total = (Integer) session.getAttribute("total");
%>

<div class="container">
    <div class = "col-md-3"></div>
    <div class="btn-group col-md-3">
        <button target="_blank" type="button" class="btn btn-success btn-lg dropdown-toggle" data-toggle="dropdown"
               >我要支付&nbsp;<span class="caret"></span></button>
        <ul class="dropdown-menu" role="menu">
            <li>
                <a href="pay.html">微信</a>
            </li>
            <li>
                <a href="pay.html">支付宝</a>
            </li>
            <li class="divider"></li>
            <li class="dropdown-header">银联</li>
            <li>
                <a href="pay.html">交通银行</a>
            </li>
            <li>
                <a href="pay.html">中国银行</a>
            </li>
            <li>
                <a href="pay.html">招商银行</a>
            </li>
            <li>
                <a href="pay.html">农业银行</a>
            </li>
            <li>
                <a href="pay.html">其他</a>
            </li>
        </ul>
    </div>

    <div class="col-md-3"><a href="total" style="text-decoration: none"><span
            style="font-size:20px;font-weight:bold;color:#008B00;margin-top:15px;">总价格:￥<%=total%></span></a>
    </div>
</div>

<script type="text/javascript">
    //生成随机数
    function play() {
        return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
    }

    //生成日期
    function getDate() {
        var date = new Date();
        var seperator1 = "/";
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
        return currentdate;
    }

    document.getElementById("order_id").innerHTML = 'hw' + play() + play();
    document.getElementById("order_date").innerHTML = getDate();
</script>

<!--手机数量增加/减少  同时修改价格-->
<script type="text/javascript">

    var count = $('#count').val();

    var priceSingle = $('#price').text();

    function countAdd() {
        count = $('#count').val();
        priceSingle = $('#price').text();
        $("#count").attr("value", parseInt(count) + 1);
    }

    function countMinus() {
        count = $('#count').val();
        if (count != 0) {
            $("#count").attr("value", parseInt(count) - 1);
        } else {
            alter('数量为0,不能再减少了')
        }
    }
</script>
</body>
</html>